home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 261 / SOMC Family Forum 261.iso / Xtras / Behavior Library.cst / 00042_Script_Video slider < prev    next >
Text File  |  1997-11-17  |  9KB  |  254 lines

  1. -- Video Time Slider
  2.  
  3.  
  4. -- behavior library version 1.1
  5. -- Control
  6.  
  7. -- requires an 'extent' cast member 
  8. -- that limits the range the slider 'slides'
  9. -- controls the MovieTime of a video sprite,
  10. -- if the sprite is playing the slider moves automatically
  11.  
  12.  
  13.  
  14. property pDuration, pMovieTime, VideoSprite
  15.  
  16. property horizontal  -- if false, vertical
  17. property extentSprite
  18. property hiliteMember  -- looks like the handle plus hilite graphics
  19. -- also holds the member of handle while hilited
  20.  
  21. property tracking
  22. property newLocH
  23. property newLocV
  24.  
  25. property sending   -- if true, sends value when parked
  26. property dynamic   -- if true and sending true, sends value while tracking
  27. property style     -- [sendAllSprites, SendSprite, Call]
  28. property addressee -- which spritenum gets the message if SendSprite or Call
  29. property name      -- Sliders identity so messages can be traced
  30. property notify_list -- list of sprites to receive event, only has 1 item this time
  31.  
  32. property min, max  -- the range the slider maps to
  33. property valrange  -- the difference of max and min, set on begin
  34. property minScreen, maxScreen -- calculated from the screen coords of the extent
  35. property currentScreenVal -- the data point in screen coords, set in tracking
  36. property extentlength -- in screen coords, set on begin
  37.  
  38. property CurrentVal
  39.  
  40. on getPropertyDescriptionList
  41.   if the currentspritenum = 0 then 
  42.     set memdefault = 0 
  43.   else
  44.     set memref = the member of sprite the currentspritenum
  45.     set castlibnum = the castlibnum of memref
  46.     set memdefault = member (the membernum of member memref + 1) of castlib castlibnum
  47.   end if
  48.   
  49.   
  50.   set description = [:]
  51.   
  52.   addprop description, #VideoSprite, [#default: 1, #format:#integer, #comment: "Video Sprite:"]
  53.   
  54.   addprop description, #extentSprite, [#default: 1, #format:#integer, #comment: "Extent Sprite:"]
  55.   
  56.   addprop description, #hiliteMember, [#default: memdefault , #format:#graphic,#comment: "Hilite Member:"]
  57.   
  58.   addprop description, #horizontal, [#default: 1, #format:#boolean,#comment: "Horizontal (if not vertical):"]
  59.   
  60.   addprop description, #dynamic, [#default: 1, #format:#boolean,#comment: "Dynamic:"]
  61.   
  62.   return description
  63. end
  64.  
  65. on getBehaviorDescription
  66.     return "Drag to slider 'handle' to enable control of video play time.  Requires additional 'extent' member which limits the handle travel range." & RETURN & "PARAMETERS:" & RETURN & "ò Video Sprite - Enter the number of sprite channel in which video is displayed." & RETURN & "ò Extent Sprite -  Enter the number of sprite channel that contains the 'extent' sprite."  & RETURN & "ò Hilite Member -  Member to display while handle is being dragged."  & RETURN & "ò Horizontal - If set, orient extent sprite horizontally, if not set orient vertically."  & RETURN & "ò Dynamic - If set, video time will be updated while handle is dragged, else when handle is released."
  67. end
  68.  
  69. on compute_val me
  70.   -- relies on tracking to update the currentScreenVal (different for Hor, Vert)
  71.   set val = 0.0
  72.   set val = float(the currentScreenVal of me) / float (the extentlength of me)
  73.   set val = val * the valrange of me
  74.   set val = val + the min of me
  75.   return val
  76. end
  77.  
  78. on send_the_val me, val
  79.   -- sets the digital video time to the val * paramter {0 - movieduration}
  80.   set pMovieTime = val * pDuration
  81.   set the movieTime of sprite VideoSprite to pMovieTime 
  82.   
  83. end
  84.  
  85.  
  86. on beginSprite me
  87.   
  88.   set pDuration = the duration of sprite VideoSprite
  89.   
  90.   set the min of me = 0.0
  91.   set the max of me = 1.0
  92.   set the sending of me = true
  93.   
  94.   --
  95.   set handle = the spritenum of me
  96.   set the tracking of me = FALSE
  97.   set the newLocH of me = the locH of sprite handle
  98.   set the newLocV of me = the locV of sprite handle
  99.   
  100.   if the horizontal of me then    
  101.     set the newLocV of me = the locV of sprite the extentSprite of me
  102.     set the minScreen of me = the left of sprite the extentSprite of me
  103.     set the maxScreen of me = the right of sprite the extentSprite of me
  104.   else -- vertical slider
  105.     set the newLocH of me = the locH of sprite the extentSprite of me  
  106.     set the minScreen of me = the left of sprite the extentSprite of me
  107.     set the maxScreen of me = the right of sprite the extentSprite of me
  108.   end if
  109.   
  110.   puppetsprite handle, TRUE  -- take this out when beginSpriteAutoPuppet fixed
  111.   
  112.   set the locH of sprite handle to the newLocH of me
  113.   set the locV of sprite handle to the newLocV of me
  114.   
  115.   set the valrange of me = the max of me - the min of me
  116.   set the extentlength of me = the maxScreen of me - the minScreen of me
  117.   
  118.   if the sending of me = FALSE then  -- check for wrong input (dyn true, send false)
  119.     set the dynamic of me = FALSE
  120.   end if
  121.   
  122.   -- set CurrentVal =  compute_val() 
  123.   
  124. end
  125.  
  126. on prepareFrame me
  127.   -- limits motion of handle to extents of extentSprite
  128.   -- and locks the handle to the track of the extentSprite
  129.   
  130.   if tracking then
  131.     set handle = the spriteNum of me
  132.     set extent =  the extentSprite of me
  133.     
  134.     if the horizontal of me then    
  135.       set the newLocH of me = the mouseH
  136.       set the newLocV of me = the locV of sprite extent
  137.       if the newLocH of me < the left of sprite extent then
  138.         set the newLocH of me = the left of sprite extent
  139.       end if
  140.       if the newLocH of me > the right of sprite extent then
  141.         set the newLocH of me = the right of sprite extent
  142.       end if
  143.       
  144.       set the currentScreenVal of me = the newLocH of me - the minScreen of me
  145.       
  146.     else -- vertical slider
  147.       set the newLocH of me = the locH of sprite extent
  148.       set the newLocV of me = the mouseV
  149.       if the newLocV of me < the top of sprite extent then
  150.         set the newLocV of me = the top of sprite extent
  151.       end if
  152.       if the newLocV of me > the bottom of sprite extent then
  153.         set the newLocV of me = the bottom of sprite extent
  154.       end if   
  155.       
  156.       set the currentScreenVal of me = the newLocV of me - the minScreen of me
  157.       
  158.     end if  -- if vertical
  159.     
  160.     set the locH of sprite handle to the newLocH of me
  161.     set the locV of sprite handle to the newLocV of me
  162.     
  163.     if the dynamic of me then
  164.       send_the_val me, compute_val (me)
  165.     end if
  166.     
  167.   else   --  end if tracking, control slider position by movieTime
  168.     
  169.     set x = float(the movieTime of sprite VideoSprite)/ float(pDuration)
  170.     
  171.     
  172.     set handle = the spriteNum of me
  173.     set extent =  the extentSprite of me
  174.     
  175.     if the horizontal of me then
  176.       set ScreenX = the left of sprite extent + (x * (the right of sprite extent - the left of sprite extent))
  177.       set the newLocH of me = screenX
  178.       set the newLocV of me = the locV of sprite extent
  179.       if the newLocH of me < the left of sprite extent then
  180.         set the newLocH of me = the left of sprite extent
  181.       end if
  182.       if the newLocH of me > the right of sprite extent then
  183.         set the newLocH of me = the right of sprite extent
  184.       end if
  185.       
  186.       set the currentScreenVal of me = the newLocH of me - the minScreen of me
  187.       
  188.     else -- vertical slider
  189.       set ScreenY = the top of sprite extent + (x * (the bottom of sprite extent - the top of sprite extent))
  190.       set the newLocH of me = the locH of sprite extent
  191.       set the newLocV of me = ScreenY
  192.       if the newLocV of me < the top of sprite extent then
  193.         set the newLocV of me = the top of sprite extent
  194.       end if
  195.       if the newLocV of me > the bottom of sprite extent then
  196.         set the newLocV of me = the bottom of sprite extent
  197.       end if   
  198.       
  199.       set the currentScreenVal of me = the newLocV of me - the minScreen of me
  200.       
  201.     end if  -- if vertical
  202.     
  203.     set the locH of sprite handle to the newLocH of me
  204.     set the locV of sprite handle to the newLocV of me
  205.     
  206.   end if
  207.   
  208.   
  209. end
  210.  
  211. on mouseDown me 
  212.   set tracking = TRUE
  213.   set temp = the member of sprite the spritenum of me
  214.   set the member of sprite the spritenum of me = member the hiliteMember of me
  215.   set the hiliteMember of me = temp
  216. end
  217.  
  218. on mouseUp me
  219.   set tracking = FALSE
  220.   set temp = the member of sprite the spritenum of me
  221.   set the member of sprite the spritenum of me = member the hiliteMember of me
  222.   set the hiliteMember of me = temp
  223.   
  224.   if the sending of me then
  225.     set x = compute_val (me)
  226.     send_the_val me, x
  227.   end if
  228.   
  229. end
  230.  
  231. on mouseUpOutside me
  232.   set tracking = FALSE
  233.   set temp = the member of sprite the spritenum of me
  234.   set the member of sprite the spritenum of me = member the hiliteMember of me
  235.   set the hiliteMember of me = temp
  236.   
  237.   if the sending of me then
  238.     set x = compute_val (me)
  239.     send_the_val me, x
  240.   end if
  241.   
  242. end
  243.  
  244. on mouseEnter me
  245.   
  246. end
  247.  
  248. on mouseLeave me
  249.   
  250. end
  251.  
  252.  
  253.  
  254.